﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PureMVC.Interfaces;
using GameEngine.Model.Data;
using System.Xml.Linq;
using GameEngine.View.Components;
using System.Collections.Generic;
using MapEngine;

namespace GameEngine.Model
{
    public class IMapDataProxyConstants<ItemVOId>
        where ItemVOId : IComparable<ItemVOId>
    {
        //public const string THINGCHANGED_NOTIFICATION = "ThingDataProxyChanged";
        //public const string THINGCHANGEDHEIGHT_NOTIFICATIONTYPE = "ThingDataProxyHeightChanged";
        //public const string MAPPOSITIONCHANGED_NOTIFICATIONTYPE = "DataProxyMapPositionChanged";
        //public const string THINGCHANGEDPOSITION_NOTIFICATIONTYPE = "ThingDataProxyPositionChanged";
        public static string CreateDataProxyName(IMapVO<ItemVOId> vo)
        {
            return CreateDataProxyName(vo.Name);
        }

        public static string CreateDataProxyName(string name)
        {
            return name + "_mapDataProxy";
        }

        public static IMapDataProxy<ItemVOId> GetMapDataProxy(string name)
        {
            return ApplicationFacade.Instance.RetrieveProxy(CreateDataProxyName(name)) as IMapDataProxy<ItemVOId>;
        }
    }

    public interface IMapDataProxy<ItemVOId> : IDataProxy, GameEngine.Libs.TileBasedMap, GameEngine.Libs.PathFinder
        where ItemVOId : IComparable<ItemVOId>
    {
        string CAMERAPOSITIONUPDATED_NOTIFICATION{get;}
        string TYPEUPDATED_NOTIFICATION { get; }
        string SCALEUPDATED_NOTIFICATION { get; }
        string TILESUPDATED_NOTIFICATION { get; }
        string TILEHEIGHTUPDATED_NOTIFICATION { get; }
        string CURSORUPDATED_NOTIFICATION { get; }

        Point TileSize { get; set; }
        float MaxHeight { get; set; }
        List<List<ITileVO>> Tiles { get; set; }
        List<IViewVO<ItemVOId>> SimpleViews { get; }

        Point CameraPosition
        {
            get;
            set;
        }

        Point Size
        {
            get;
        }

        float Scale
        {
            get;
            set;
        }

        TileType TileType { get; set; }

        MapType MapType { get; set; }

        Cursor Cursor { get; set; }

        IMapVO<ItemVOId> VO
        {
            get;
        }

        float? GetTileHeight(Point position);

        void SetTileHeight(Point position, float height);

        Point GetTileFromPosition(Point position);

        ITileVO GetTile(Point position);

        //void LoadFromXML(XDocument doc);

        XDocument SaveToXML();

        void Tick();

        void GenerateHeightsFromPerlin(Point origin, float frequency, float amplitude, float persistence, int octaves, int seed);

        int DistanceInTiles(Point position, Point position2);

        Point GetNearestEmptyPosition(IThingDataProxy<ItemVOId> mover, IThingDataProxy<ItemVOId> destiny);

        void CreateTiles(Point size);
    }
}
